package com.welink.cmp.convertor;

import com.welink.cmp.dao.metadata.dataobject.HostDO;
import com.welink.cmp.domain.metadata.Host;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 主机转换器
 */
public class HostConvertor {

    public static HostDO toDataObject(Host host) {
        if (host == null) {
            return null;
        }
        HostDO hostDO = new HostDO();
        hostDO.setId(host.getId());
        hostDO.setAssetsId(host.getAssetsId());
        hostDO.setSn(host.getSn());
        hostDO.setName(host.getName());
        hostDO.setVendor(host.getVendor());
        hostDO.setBrand(host.getBrand());
        hostDO.setModel(host.getModel());
        hostDO.setModelAlias(host.getModelAlias());
        hostDO.setUnitSize(host.getUnitSize());
        hostDO.setRackNo(host.getRackNo());
        hostDO.setRackUnitPosition(host.getRackUnitPosition());
        hostDO.setDataCenterCode(host.getDataCenterCode());
        hostDO.setExpirationTime(host.getExpirationTime());
        hostDO.setLaunchedTime(host.getLaunchedTime());
        hostDO.setIsVirtualDevice(host.getIsVirtualDevice());
        hostDO.setCpuCores(host.getCpuCores());
        hostDO.setMemoryCapacity(host.getMemoryCapacity());
        hostDO.setDiskCapacity(host.getDiskCapacity());
        hostDO.setGpuModel(host.getGpuModel());
        hostDO.setBmcIp(host.getBmcIp());
        hostDO.setInnerIp(host.getInnerIp());
        hostDO.setOuterIp(host.getOuterIp());
        hostDO.setIngressIp(host.getIngressIp());
        hostDO.setOs(host.getOs());
        hostDO.setSupportedRaid(host.getSupportedRaid());
        hostDO.setHardwareDetail(host.getHardwareDetail());
        hostDO.setSoftwareDetail(host.getSoftwareDetail());
        hostDO.setRefId(host.getRefId());
        hostDO.setRefName(host.getRefName());
        hostDO.setAccountId(host.getAccountId());
        hostDO.setChargeType(host.getChargeType());
        hostDO.setStatus(host.getStatus());
        hostDO.setCreateTime(host.getCreateTime());
        hostDO.setUpdateTime(host.getUpdateTime());
        hostDO.setCreateBy(host.getCreateBy());
        hostDO.setUpdateBy(host.getUpdateBy());
        return hostDO;
    }

    public static Host toDomainObject(HostDO hostDO) {
        if (hostDO == null) {
            return null;
        }
        Host host = new Host();
        host.setId(hostDO.getId());
        host.setAssetsId(hostDO.getAssetsId());
        host.setSn(hostDO.getSn());
        host.setName(hostDO.getName());
        host.setVendor(hostDO.getVendor());
        host.setBrand(hostDO.getBrand());
        host.setModel(hostDO.getModel());
        host.setModelAlias(hostDO.getModelAlias());
        host.setUnitSize(hostDO.getUnitSize());
        host.setRackNo(hostDO.getRackNo());
        host.setRackUnitPosition(hostDO.getRackUnitPosition());
        host.setDataCenterCode(hostDO.getDataCenterCode());
        host.setExpirationTime(hostDO.getExpirationTime());
        host.setLaunchedTime(hostDO.getLaunchedTime());
        host.setIsVirtualDevice(hostDO.getIsVirtualDevice());
        host.setCpuCores(hostDO.getCpuCores());
        host.setMemoryCapacity(hostDO.getMemoryCapacity());
        host.setDiskCapacity(hostDO.getDiskCapacity());
        host.setGpuModel(hostDO.getGpuModel());
        host.setBmcIp(hostDO.getBmcIp());
        host.setInnerIp(hostDO.getInnerIp());
        host.setOuterIp(hostDO.getOuterIp());
        host.setIngressIp(hostDO.getIngressIp());
        host.setOs(hostDO.getOs());
        host.setSupportedRaid(hostDO.getSupportedRaid());
        host.setHardwareDetail(hostDO.getHardwareDetail());
        host.setSoftwareDetail(hostDO.getSoftwareDetail());
        host.setRefId(hostDO.getRefId());
        host.setRefName(hostDO.getRefName());
        host.setAccountId(hostDO.getAccountId());
        host.setChargeType(hostDO.getChargeType());
        host.setStatus(hostDO.getStatus());
        host.setCreateTime(hostDO.getCreateTime());
        host.setUpdateTime(hostDO.getUpdateTime());
        host.setCreateBy(hostDO.getCreateBy());
        host.setUpdateBy(hostDO.getUpdateBy());
        return host;
    }

    public static List<HostDO> toDataObjectList(List<Host> hosts) {
        return hosts.stream()
                .map(HostConvertor::toDataObject)
                .collect(Collectors.toList());
    }

    /**
     * @param hostDOs
     * @return
     */
    public static List<Host> toDomainObjectList(List<HostDO> hostDOs) {
        return hostDOs.stream()
                .map(HostConvertor::toDomainObject)
                .collect(Collectors.toList());
    }
}